package com.kmproject.haifu.mvp.model;

import android.annotation.SuppressLint;
import android.app.Application;

import com.blankj.utilcode.util.PhoneUtils;
import com.google.gson.Gson;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.kmproject.haifu.mvp.contract.PersonalHomePageActivityContract;
import com.kmproject.haifu.mvp.model.api.Api;
import com.kmproject.haifu.mvp.model.api.service.UserService;
import com.kmproject.haifu.mvp.model.entity.ResultBean;
import com.kmproject.haifu.mvp.model.entity.beans.HouseInfoTitleBean;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.model.entity.beans.MyCommonPublishCountBean;
import com.kmproject.haifu.mvp.model.entity.beans.UserHomePageBean;
import com.kmproject.haifu.mvp.model.entity.beans.ViewStoreInfoBean;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observable;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 07/31/2019 10:34
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class PersonalHomePageActivityModel extends BaseModel implements PersonalHomePageActivityContract.Model {
    @Inject
    Gson mGson;
    @Inject
    Application mApplication;
    private UserService userService;

    @Inject
    public PersonalHomePageActivityModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
        userService = mRepositoryManager.obtainRetrofitService(UserService.class);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<ResultBean<UserHomePageBean>> getUserHomePageInfo(String userId) {
        return userService.getUserHomePageInfo(userId);
    }

    @Override
    public Observable<ResultBean<MyCommonPublishCountBean>> myCommonPublishCount(String countType) {//publish:我求租和租房发布，collection：我的收藏
        return userService.myCommonPublishCount(Api.MY_COMMON_PUBLISH_COUNT + countType);
    }

    @SuppressLint("MissingPermission")
    @Override
    public Observable<ResultBean<ViewStoreInfoBean>> viewStoreInfo(String storeId) {
        return userService.viewStoreInfo(storeId, PhoneUtils.getDeviceId());
    }

    @Override
    public Observable<ResultBean> follow(Map<String, Object> maps) {
        return userService.userAttentionAdd(creatRequestBody(maps, mGson));
    }

    @Override
    public Observable<ResultBean> unFollow(Map<String, Object> maps) {
        return userService.userAttentionCancel(creatRequestBody(maps, mGson));
    }

    @Override
    public Observable<ResultBean<List<HousePayWayBean>>> getAreaList(String url, String value, String category) {
        return userService.getAreaTree(url, value, category);
    }

    @Override
    public Observable<ResultBean<List<HousePayWayBean>>> dictList4Category(String value, String category) {
        return userService.dictList(value, category);
    }

    @Override
    public Observable<ResultBean<List<HouseInfoTitleBean>>> dictList4Screen(String value, String category) {
        return null;
    }
}